package com.jianyun.jyzs.http;


import android.util.Log;

import com.jianyun.jyzs.bean.EnNatureResponse;

import java.util.HashMap;
import java.util.List;

import com.jianyun.jyzs.utils.RceLog;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by mlli on 2017/11/21.
 * 获取企业性质
 */

public class EnNatureHelper {
    public interface EnNatureListener {
        void getSuccess(List<EnNatureResponse.EnNatureBean> list);

        void getFail(String msg);
    }

    public static void getEnNatureList(String enterpriseCode, final EnNatureListener listener) {
        /*Api api = RetrofitHelper.builderbch().create(Api.class);
        HashMap<String, String> map = new HashMap<>();
        map.put("enterpriseCode", enterpriseCode);
        api.getEntNature(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<EnNatureResponse>() {
                    @Override
                    protected void onResponse(EnNatureResponse response) {
                        //Log.i("test","企业性质："+response.toString());
                        if (response.isResult()) {
                            List<EnNatureResponse.EnNatureBean> list = response.getList();
                            if (listener != null) listener.getSuccess(list);
                        } else {
                            RceLog.d("lml", response.toString());
                        }

                    }

                    @Override
                    protected void onException(String msg) {
                        if (listener != null) listener.getFail(msg);
                    }
                });*/
    }

    /**
     * 新的获取企业性质
     *
     * @param enterpriseCode
     */
    public static void getNewEnNatureList(String enterpriseCode, final EnNatureListener listener) {
        Api api = RetrofitHelper.builderErpRoot().create(Api.class);
        HashMap<String, String> map = new HashMap<>();
        map.put("method", "crm_qyxz");
        api.getNewEntNature(map)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new CustomCallback<EnNatureResponse>() {
                    @Override
                    protected void onResponse(EnNatureResponse response) {
                        Log.i("test", "企业性质：" + response.toString());
                        if (response.isResult()) {
                            List<EnNatureResponse.EnNatureBean> list = response.getData();
                            if (listener != null) listener.getSuccess(list);
                        } else {
                            RceLog.d("lml", response.toString());
                        }

                    }

                    @Override
                    protected void onException(String msg) {
                        if (listener != null) listener.getFail(msg);
                    }
                });
    }
}
